home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / TKERN091.ZIP / INCLUDE / SYS / TASK.H < prev    next >
Text File  |  1994-03-04  |  3KB  |  82 lines

  1. /*
  2.  *  This file forms part of "TKERN" - "Troy's Kernel for Windows".
  3.  *
  4.  *  Copyright (C) 1994  Troy Rollo <troy@cbme.unsw.EDU.AU>
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #ifndef __task_h
  22. #define __task_h
  23.  
  24. #define    UFILE_MAX    20
  25. #define    TNTASK        20 /* Total number of tasks */
  26.  
  27. #define    HTASK_FLEDGELING    ((HTASK) -1)
  28.  
  29. struct    task
  30. {
  31.     HTASK    hTask;
  32.     short    pid;
  33.     int    iFledgeling;    /* For our fork()            */
  34.     int    iParent;    /* For easy reference during fork/exec    */
  35.     int    nChildren;    /* Number of children executed        */
  36.     int    nZombies;    /* Number of zombies waiting for reaping */
  37.     HFILE    files[UFILE_MAX];
  38.     char    **argv;
  39.     char    **envp;
  40.     unsigned nFlags;
  41.     int    nError;
  42. };
  43.  
  44. #define    TF_ASLEEP    1    /* Task is sleeping        */
  45. #define    TF_EXEC        2    /* Task is execing a child    */
  46.  
  47. /* An MS-Windows TASK handle is almost, but not quite, entirely unlike a process ID.
  48.  * While the task is running, it uniquely identifies the task. The difference is, if
  49.  * the parent process isn't careful, the task may terminate, and a new one may be
  50.  * started with the same task handle. We need to have the parent task being capable
  51.  * of knowing when its children die. Consequently, we need to keep a record of all
  52.  * processes entering and leaving the system. If the process in question was started
  53.  * using tkexec, and it exits it becomes a zombie until the parent waits for it.
  54.  *
  55.  * If the parent exits first, its parent pid becomes 1 (the process 1 doesn't exist,
  56.  * but this mirrors Ken's OS), its parent hTask becomes 0, and the process is reaped
  57.  * automatically on exit. This is getting scarily close to POSIX realities.
  58.  *
  59.  * Valid task handles are 2-32767. If a process exits while its child still lives,
  60.  * the child is reaped on exit. Essentially, we try to maintain parent-child
  61.  * relationships even though windows itself doesn't.
  62.  *
  63.  * We cannot maintain parent-child relationships if the child is WinExec'd. See
  64.  * tkern.c for the reasoning. I think the cause is a Windows bug (gasp).
  65.  *
  66.  * One wonders why NT doesn't do something like this.
  67.  */
  68.  
  69. struct    tk_process
  70. {
  71.     short    pid;        /* 0 for an empty entry                    */
  72.     short    pidParent;    /* 1 for a task without a parent            */
  73.     HTASK    hTask;        /* 0 for a zombie                    */
  74.     HTASK    hTaskParent;    /* 0 for a task without a parent            */
  75.     int    iParent;    /* -1 if the parent wasn't tkexec'd            */
  76.     int    nRetCode;    /* Return code of the program                */
  77. };
  78.  
  79. #define    N_TKPROCS    100    /* If we exceed this, we are in deep benji by-product    */
  80.  
  81. #endif /* __task_h */
  82.